const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../utils/user.js');

//获取应用实例
const app = getApp()
Page({
  data: {
    show:true,
    word:'',
    goodsCount: 0,
    newGoods: [],
    hotGoods: [],
    topics: [],
    top10: [],
    // brands: [],
    floorGoods: [],
    banner: [],
    channel: [],
    remindValue: ['', '', '送'],
    plusFlag: ['', '+', ' '],
    vipCategoryL2:[],
    integralCategoryL2:[]
  },
  onShareAppMessage: function() {
    return {
      title: '爱联商圈小程序',
      desc: '爱联商圈小程序商城',
      path: '/pages/index/index'
    }
  },

  onPullDownRefresh() {
    wx.showNavigationBarLoading() //在标题栏中显示加载
    this.setData({
      show: true
    });
    this.getIndexData();
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },

  getIndexData: function() {
    let that = this;
    util.request(api.IndexUrl).then(function(res) {
      if (res.errno === 0) {
        that.setData({
          goodsCount: res.data.goodsCount,
          word: res.data.word,
          newGoods: res.data.newGoodsList,
          hotGoods: res.data.hotGoodsList,
          top10: res.data.top10,
          topics: res.data.topicList,
          // brands: res.data.brandList,
          floorGoods: res.data.floorGoodsList,
          banner: res.data.banner,
          channel: res.data.channel,
          vipCategoryL2:res.data.memberGoodsNum,
          integralCategoryL2: res.data.integralGoodsNum
        });
        // console.log(that.data.vipCategoryL2)
        // console.log(that.data.integralCategoryL2)
        var memberGoodsNum = res.data.memberGoodsNum
        var integralGoodsNum = res.data.integralGoodsNum
        wx.setStorageSync("memberGoodsNum", memberGoodsNum)
        wx.setStorageSync("integralGoodsNum", integralGoodsNum)
        app.globalData.memberGoodsNum = memberGoodsNum
        app.globalData.integralGoodsNum = integralGoodsNum
        // if (that.data.word!=''){
        //   wx.showModal({
        //     title: '提示',
        //     content: that.data.word,
        //     showCancel: false
        //   })
        // }
      }
    });
  },
  confirmTrue:function(){
    this.setData({
      show:false
    });
  },
  onLoad: function(options) {
    this.getIndexData();
  },
  onReady: function() {
    // 页面渲染完成
  },
  onShow: function() {
    
    // 页面显示
  },
  onHide: function() {
    // 页面隐藏
  },
  onUnload: function() {
    // 页面关闭
  },
})